package Visitor;

import Arbori.Nod;
import Functii.Elementare.*;
import Functii.Trigonometrice.*;
import Operator.*;

public class DerivareVisitor extends Visitor{
	String rez;
	ToStringVisitor tsv = new ToStringVisitor();
	
	public DerivareVisitor(){
		this.rez = "";
	}
	public DerivareVisitor(String r){
		this.rez = r;
	}
	public String getRez() {
		return rez;
	}
	public void setRez(String rez) {
		this.rez = rez;
	}
	public ToStringVisitor getTsv() {
		return tsv;
	}
	public void setTsv(ToStringVisitor tsv) {
		this.tsv = tsv;
	}
	
	
	public void visit(Plus p) {
		if(p.getfStang() != null && p.getfDrept() != null){
			visit(p.getfStang());
			String s1 = this.rez;
			visit(p.getfDrept());
			String s2 = this.rez;
			rez = p.concatTermeni(s1, s2);
		}
	}

	public void visit(Minus m) {
		if(m.getfStang() != null && m.getfDrept() != null){
			visit(m.getfStang());
			String s1 = this.rez;
			visit(m.getfDrept());
			String s2 = this.rez;
			rez = m.concatTermeni(s1, s2);
		}
	}

	public void visit(Produs p) {
		if(p.getfStang() != null && p.getfDrept() != null){
			visit(p.getfStang());
			String f1d = this.rez;
			visit(p.getfDrept());
			String f2d = this.rez;
			p.getfStang().acceptVisitor(tsv);
			String f1 = tsv.getS();
			p.getfDrept().acceptVisitor(tsv);
			String f2 = tsv.getS();
			rez = Plus.concatTermens(Produs.concatTermens(f1d, f2), Produs.concatTermens(f1, f2d));
		}
	}

	public void visit(Cat c) {
		if(c.getfStang() != null && c.getfDrept() != null){
			visit(c.getfStang());
			String f1d = this.rez;
			visit(c.getfDrept());
			String f2d = this.rez;
			c.getfStang().acceptVisitor(tsv);
			String f1 = tsv.getS();
			c.getfDrept().acceptVisitor(tsv);
			String f2 = tsv.getS();
			rez = Cat.concatTermens(Minus.concatTermens(Produs.concatTermens(f1d, f2), 
					Produs.concatTermens(f1, f2d)), Putere.concatTermens(f2));
		}
	}

	public void visit(Sin s) {
		if(s.getfStang() != null){
			visit(s.getfStang());
			String fsd = this.rez;
			s.getfStang().acceptVisitor(tsv);
			String f = tsv.getS();
			rez = Produs.concatTermens(Cos.concatTermens(f), fsd);
		}
	}

	public void visit(Cos c) {
		if(c.getfStang() != null){
			visit(c.getfStang());
			String fsd = this.rez;
			c.getfStang().acceptVisitor(tsv);
			String f = tsv.getS();
			rez = Produs.concatTermens(fsd, Sin.concatTermens(f));
		}
	}

	public void visit(Tg t) {
		// TODO Auto-generated method stub
		
	}

	public void visit(Ctg c) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void visit(Arcsin as) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void visit(Arccos ac) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void visit(Arctg at) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void visit(Arcctg ac) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void visit(Sinh sh) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void visit(Cosh ch) {
		// TODO Auto-generated method stub
		
	}

	public void visit(Constanta c) {
		rez = "0";
	}

	public void visit(Necunoscuta n) {
		rez = "1";
	}

	public void visit(Radical r) {
		if(r.getfStang() != null){
			visit(r.getfStang());
			String f = this.rez;
			rez = Cat.concatTermens("1", Produs.concatTermens("2", Radical.concatTermens(f)));
		}
	}

	public void visit(Putere p) {
		if(p.getfStang() != null){
			visit(p.getfStang());
			String f= this.rez;
			rez = Produs.concatTermens("2", f);
		}
	}

	@Override
	public void visit(Exp e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void visit(Log l) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void visit(Nod n) {
		// TODO Auto-generated method stub
		
	}

}
